package com.example.designdemo.singleton;

public class Singleton2 {
    private static Singleton2 singleton= null;

    /* 私有构造方法，防止被实例化 */
    private Singleton2(){

    }

    /**
     * 创建
     */
    private static synchronized void syncInit(){
        if (singleton==null){
            singleton = new Singleton2();
        }
    }

    /**
     * 获取
     * @return
     */
    public static Singleton2 getSingleton(){
        if (singleton==null){
            syncInit();
        }
        return singleton;
    }
}
